package bb.lanxing.lib.widget;

import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;
import androidx.viewpager.widget.ViewPager;

public class LockableViewPager extends ViewPager {
    private boolean mScrollable;

    public LockableViewPager(Context context) {
        super(context);
        this.mScrollable = true;
    }

    public LockableViewPager(Context context, AttributeSet attributeSet) {
        super(context, attributeSet);
        this.mScrollable = true;
    }

    @Override
    public boolean onTouchEvent(MotionEvent motionEvent) {
        if (motionEvent.getAction() == 0) {
            try {
                if (this.mScrollable) {
                    return super.onTouchEvent(motionEvent);
                }
            } catch (IllegalArgumentException e) {
                e.printStackTrace();
            }
            return false;
        }
        try {
            return super.onTouchEvent(motionEvent);
        } catch (IllegalArgumentException e2) {
            e2.printStackTrace();
            return false;
        }
    }

    @Override
    public boolean onInterceptTouchEvent(MotionEvent motionEvent) {
        try {
            if (!this.mScrollable) {
                return false;
            }
            return super.onInterceptTouchEvent(motionEvent);
        } catch (IllegalArgumentException e) {
            e.printStackTrace();
            return false;
        }
    }

    public boolean isScrollable() {
        return this.mScrollable;
    }

    public void setScrollable(boolean z) {
        this.mScrollable = z;
    }
}
